package org.jeecg.modules.fund.util;

import cn.hutool.Hutool;
import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateRange;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.lang.Dict;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.modules.fund.service.IFundTradeService;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.springframework.beans.factory.annotation.Autowired;

import javax.print.Doc;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Deprecated
@Slf4j
public class TestUtil {
    public static void main(String args[]) {
        log.info(DateUtil.isWeekend(new Date()) + "");
        //log.info();
//        Document document;
//        try {
//            getMaxPage();
//            // 查询基金估值
//            document = Jsoup.connect("https://www.dayfund.cn/prevalue_2.html").get();
//            Element table = document.select("table").last();
//            Element tbody = table.select("tbody").first();
//            Elements trs = tbody.select("tr");
//            List<JSONArray> dataList = new ArrayList<>();
//            for (Element tr : trs) {
//                Elements tds = tr.select("td");
//                JSONArray array = new JSONArray();
//                for (Element td : tds) {
//                    array.add(td.text());
//                }
//                dataList.add(array);
//            }
//        } catch (Exception e) {
//
//        }
    }

    public static Integer getMaxPage(){
        try {
            Document document = Jsoup.connect("https://www.dayfund.cn/prevalue.html").get();
            Element pageElement = document.select("div.pager").last();
            Elements pages = pageElement.select("a");
            int maxPage = 0;
            if(pages.size() > 0) {
                Element maxPageEle = pages.get(pages.size() - 2);
                maxPage = Integer.parseInt(maxPageEle.text());
            }
            return maxPage;
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
